#pragma once

#include "config.h"
#include "market_data/market_data.h"
#include "core/order_manager.h"
#include "risk/risk_manager.h"
#include "core/execution.h"
#include "utils/logger.h"
#include <memory>
#include <atomic>
#include <thread>
#include <vector>
#include <map>
#include <chrono>

namespace hft {

// 前向声明
class MarketDataHandler;
class Strategy;

class TradingSystem {
public:
    explicit TradingSystem(const Config& config);
    ~TradingSystem();

    // 初始化系统组件
    void initializeComponents();
    
    // 启动交易系统
    void start();
    
    // 停止交易系统
    void stop();
    
    // 检查系统是否运行
    bool isRunning() const { return m_running.load(); }

private:
    // 主事件循环
    void eventLoop();

    // 系统配置
    const Config& m_config;
    
    // 系统组件
    std::unique_ptr<MarketDataHandler> m_marketDataHandler;
    std::unique_ptr<OrderManager> m_orderManager;
    std::unique_ptr<RiskManager> m_riskManager;
    std::unique_ptr<ExecutionEngine> m_executionEngine;
    
    // 线程管理
    std::vector<std::thread> m_workerThreads;
    std::atomic<bool> m_running{false};
    std::atomic<bool> m_shouldStop{false};
};